<?php

class DaoQuery {

  function _count($sql) {
    $actualSQL = 'select count(*) as row_count '.$sql;
    $rs = mysql_query ($actualSQL);
    $errNo = mysql_errno();
    if ($errNo != 0) {
      user_error('Data access error: '.$errNo. ': ' . mysql_error() . '. SQL in query "'.get_class($this).'": ' . $sql);
      exit;
    }
    $row = mysql_fetch_array($rs);
    $count = (int) $row['row_count'];
    mysql_free_result($rs);
    return $count;
  }

  function convert_to_string($value) {
    return "$value";
  }

  function convert_to_int($value) {
    return (int) $value;
  }

  function convert_int_to_boolean($value) {
    return (((int) $value) != 0);
  }

  function escape_value($value) {
    if (is_bool($value)) {
      return $value ? 1 : 0;
    } else if (is_int($value)) {
      return $value;
    } else {
      return "'" . mysql_real_escape_string($value) . "'";
    }
  }

  function get_generated_id() {
    return mysql_insert_id();
  }
}

?>